import pymysql


class DBTools:
    @classmethod
    def __get_connect(cls):
        conn = pymysql.connect(host='localhost', port=3306, user='root', password='root', database='class_db',
                               charset='utf8')
        return conn

    @classmethod
    def select_one(cls, sql):
        cursor = None
        conn = None
        res = None
        try:
            conn = cls.__get_connect()
            cursor = conn.cursor()
            cursor.execute(sql)
            res = cursor.fetchone()

        except Exception as e:
            print('出错了拉！',e)
        finally:
            cursor.close()
            conn.close()
            return res

if __name__ == '__main__':
    sql = 'select * from student;'
    print(DBTools.select_one(sql))
